package com.example.flutter_app;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
  private static final String CHANNEL = "samples.flutter.io/battery";
  MethodChannel methodChannel;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GeneratedPluginRegistrant.registerWith(this);
    methodChannel=new MethodChannel(getFlutterView(), CHANNEL);
    methodChannel.invokeMethod("getBatteryLevel", "", new MethodChannel.Result() {
        @Override
        public void success(Object o) {
            String s=(String)o;
            Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
        }

        @Override
        public void error(String s, String s1, Object o) {

        }

        @Override
        public void notImplemented() {

        }
    });
    methodChannel.setMethodCallHandler(

            new MethodChannel.MethodCallHandler() {
                @Override
                public void onMethodCall(MethodCall call, MethodChannel.Result result) {
                    // 在这个回调里处理从Flutter来的调用
                    if (call.method.equals("getBatteryLevel")){
                        getBatteryLevel();
                    }



                }
            }

    );
    new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
            new MethodChannel.MethodCallHandler() {
              @Override
              public void onMethodCall(MethodCall call, MethodChannel.Result result) {
                // 在这个回调里处理从Flutter来的调用
                        if (call.method.equals("getBatteryLevel")){
                            getBatteryLevel();
                        }



              }
            });
  }
   void getBatteryLevel(){
      Intent intent=new Intent(MainActivity.this,BitmapActivity.class);
      startActivity(intent);
   }

}
